package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.ChooseId;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;


public class AnalyzeChooseId implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        //*WT,868976030203477,V4,CHOOSEID,171333,0,171351,V,0.0000,S,0.0000,W,0.00,0,170721,FFFFFFFD#
        //解密
        String[] split = parseCommand(originalData);
        String imei=split[1];
        String commandNumber=split[4];
        //0:IMEID 1:ICCID 如果是iccid来标识设备，后面就填写imeid，如果是imeid来标识设备，后面就填写iccid
        String idParam=split[5];
        //时间（时分秒）
        String time=split[6];
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];
        //设备状态
        String deviceStatus = split[15];
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        ChooseId chooseId = new ChooseId();
        chooseId.setCommandNumber(commandNumber);
        chooseId.setDeviceDate(date);
        chooseId.setImei(imei);
        chooseId.setDeviceStatus(deviceStatus);
        chooseId.setDeviceTime(time);
        chooseId.setMqLocationData(mqLocationData);
        chooseId.setIdParam(idParam);
        return structureMessage(Constants.REPLY,Constants.CMD_CHOOSE_ID,false,"",chooseId);
    }
}
